const app = getApp()
const publicFun = require('/utils/public.js')
import { getClimateActionTJ, getClimateActionUserHistory } from '/utils/request'
Page({
  data: {
    pageindex: 1,
    myClimeteList: []
  },
  onLoad() {
    this.setData({
      myClimeteList: [],
      systemInfo: app.globalData.systemInfo
    });
    this.getTJList();
    this.getList(this.data.pageindex);
  },
  WaterfallFlowTap(e) {
    let data = e.currentTarget.dataset;
    my.navigateTo({
      url: '/pages/detail/detail?ssuserid='+app.globalData.userid+'&ssid='+data.wallid
    })
  },
  async getTJList() { 
    try{
      var params = {
        userid: app.globalData.userid,
        zhouqitype: 0
      }
      const res = await getClimateActionTJ(params)
      if(res.S == 1){
        let data = res;
        this.setData({ myClimateData: data })
      }else{
        publicFun.showToast(res.M ? res.M : '加载失败')
      }
    }catch(e){
      publicFun.showToast('失败，请稍后再试')
    }
  },
  async getList(pageindex) { 
    try{
      my.showLoading();
      var params = {
        userid: app.globalData.userid,
        pageindex: pageindex,
      }
      const res = await getClimateActionUserHistory(params)
      my.hideLoading();
      if(res.S == 1){
        if(res.L.length > 0){
          res.L.forEach(item => {
            item.Des = publicFun.Base64.decode(item.Des);
            this.data.myClimeteList.push(item);
          })
          this.setData({
            myClimeteList: this.data.myClimeteList,
          });
        }else{
          publicFun.showToast("已经加载到底啦")
        }
      }else{
        publicFun.showToast(res.M ? res.M : '加载失败')
      }
    }catch(e){
      my.hideLoading();
      publicFun.showToast('失败，请稍后再试')
    }
  },
  onReachBottom() {
    const newPage = this.data.pageindex + 1;
    this.setData({pageindex: newPage});
    this.getList(newPage)
  },
});
